package com.eascs.admin.o2o.loanAccount.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.account.account.AccountEntity;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.o2o.internal.util.BaseUtils;
import com.eascs.admin.o2o.loan.service.O2oChargeSituationService;
import com.eascs.admin.o2o.loanAccount.entity.O2oLoanapplyAccountEntity;
import com.eascs.admin.o2o.loanAccount.service.Io2oLoanapplyAccountService;
import com.eascs.admin.o2o.loanAccount.serviceimpl.O2oLoanapplyAccountservice;
import com.eascs.admin.o2o.loanAccount.vo.O2oCollectFeesVo;
import com.eascs.app.dao.PageResult;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.tag.MenuTag;

@Controller
@RequestMapping("/loanAccount")
public class LoanAccountController extends BaseMasterViewController {

	@Autowired
	Io2oLoanapplyAccountService o2oLoanapplyAccountService;
	
	@Autowired
	O2oLoanapplyAccountservice o2oLoanapplyAccountService1;

	@Autowired
	O2oChargeSituationService o2oChargeSituationService;

	/*@RequestMapping("/test")
	public String test() {
		o2oLoanapplyAccountService1.ChargingJQtest();
		return "/loanAccount/index";
	}*/
	

	/**
	 * @Title: index
	 * @Description: 贷款单账户余额查询
	 * @author 张庆奇
	 * @param vo
	 * @return
	 * @return String
	 * @throws @date
	 *             2017年11月30日 下午5:04:32
	 */
	@RequestMapping("/index")
	public String index(O2oCollectFeesVo vo) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "LoanAccountBalance");
		vo.setPageSize(BaseUtils.PAGE_SIZE);
		PageResult<Object[]> pageResult = o2oLoanapplyAccountService.findLoanAccountByPage(vo);
		String[] titles = {"姓名", "单号", "申请状态","缴费状态" };
		SelectDataOption[] selectDataOptions = {null,  null,  new SelectDataOption("SQZT"), new SelectDataOption("OTO_BZJ_GLF") };
		Button[] moreButtons = new Button[] { ButtonHelper.createOpenButton("账户金额", "/loanAccount/balance_info?loanapplyNo="),ButtonHelper.createOpenButton("交易明细", "/loanAccount/trade_detail?loanapplyNo=") };
		StringBuffer pageUrl=new StringBuffer("/loanAccount/index");
		String loanName=vo.getLoanName()==null?"":vo.getLoanName();
		String billCode=vo.getBillCode()==null?"":vo.getBillCode();
		pageUrl.append("?billCode="+billCode);
		pageUrl.append("&loanName="+loanName);
		pageUrl.append("&pageIndex=");
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, pageUrl.toString());
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setBuildPagingNavigation(true);
		paginationInfo.setFirstRenderColumnIndex(1);
		paginationInfo.setMoreButtons(moreButtons);
		ViewContext.put("paginationInfo", paginationInfo);
		ViewContext.put("vo", vo);
		return "/loanAccount/index";
	}
	
	/**
	 * @Title: balanceInfo
	 * @Description: 余额详情页面
	 * @author 张庆奇 
	 * @param loanapplyNo
	 * @return
	 * @return String
	 * @throws
	 * @date 2017年12月11日 下午3:29:57
	 */
	@RequestMapping("/balance_info")
	public String balanceInfo(String loanapplyNo){
		//管理费
		AccountEntity glfAccount=	o2oChargeSituationService.queryLoanAccount(loanapplyNo,"312");
		ViewContext.put("glfAccount", glfAccount);
		//保证金
		AccountEntity bzjAccount=	o2oChargeSituationService.queryLoanAccount(loanapplyNo,"311");
		ViewContext.put("bzjAccount", bzjAccount);
		//风险补偿金
		AccountEntity fxbcjAccount=	o2oChargeSituationService.queryLoanAccount(loanapplyNo,"313");
		ViewContext.put("fxbcjAccount", fxbcjAccount);
		return "/loanAccount/balance_info";
	}
	
	/**
	 * @Title: tradeDetail
	 * @Description: 贷款单账户交易明细
	 * @author 张庆奇
	 * @param loanapplyNo
	 * @return
	 * @return String
	 * @throws
	 * @date 2017年12月11日 下午3:31:23
	 */
	@RequestMapping("/trade_detail")
	public String tradeDetail(String loanapplyNo) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "trade_detail");
		O2oLoanapplyAccountEntity loanapplyAccountEntity = o2oLoanapplyAccountService
				.getEntityByLoanapplyNo(loanapplyNo);
		if (loanapplyAccountEntity != null) {
			ViewContext.put("accountId", loanapplyAccountEntity.getAccountNo());
		}
		return "/loanAccount/trade_detail";
	}

	

}
